/* 
 * File:   StringUtils.cpp
 * Author: dell
 * 
 * Created on 2012年4月3日, 上午12:32
 */


#include "StringUtils.h"
#include <stdlib.h>
#include <string.h>

using namespace std;

namespace Rapid{

    StringUtils::StringUtils() {
    }

    StringUtils::~StringUtils() {
    }


    char* StringUtils::split(vector<const char*>& retarray, const char* cstr, char sp){
        if(!cstr)return NULL;
        char* newcstr = strdup(cstr);
        char* tcstr = newcstr;
        char* pos;
        while(pos = strchr(newcstr, sp)){
            *pos = 0;
            retarray.push_back(newcstr);
            newcstr = pos+1;
        }
        retarray.push_back(newcstr);
        return tcstr;
    }
    
    
    char* StringUtils::replace(const char* str, char srcchr, char descchr){
        char* newstr = (char*)::strdup(str); //malloc(strlen(str));
        size_t n = strlen(newstr);
        for(int i=0; i<n; i++){
            if(newstr[i] == srcchr){
                newstr[i] = descchr;
            }
        }
        return newstr;
    }
    
    
}


